﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace RoleHelper
{
    class NPC : ICombatible
    {
        
        private int ID;
        private string nombre;
        private int vidaMax;
        private int vidaActual;
        private int ppMax;
        private int ppActual;
        private int nivel;
        private char sexo;
        private bool masked;
        private int BO;
        private int BD;
        private bool bomasked;
        private bool bdmasked;
        private char estado;
        private int turnos;
        private List<habilidad> habilidades;
        private List<listahechizos> lista_hehcizos;
        private TInventario Inventario;

        public NPC()
	    {
            habilidades = new List<habilidad>();
            lista_hehcizos = new List<listahechizos>();
	    }

        public NPC( string nom, int lvl , int vMax, int pMax, char sex, bool mask, int bo, int bd )
        {
            nombre = nom;
            vidaMax = vMax;
            ppMax = pMax;
            sexo = sex;
            masked = mask;
            nivel = lvl;
            vidaActual = vMax;
            ppActual = pMax;
            BO = bo;
            BD = bd;
            bomasked = true;
            bdmasked = true;
            habilidades = new List<habilidad>();
            lista_hehcizos = new List<listahechizos>();
            estado = 'A';
            turnos = 0;
        }

        public NPC(string nom, int lvl, int vMax, int pMax, char sex, bool mask, int bo, int bd, int rg, int cst1, int cst2, string name, string desc, string atr1, string atr2)
        {
            nombre = nom;
            vidaMax = vMax;
            ppMax = pMax;
            sexo = sex;
            masked = mask;
            nivel = lvl;
            vidaActual = vMax;
            ppActual = pMax;
            BO = bo;
            BD = bd;
            bomasked = true;
            bdmasked = true;
            habilidad nueva = new habilidad(rg, cst1, cst2, name, desc, atr1, atr2);
            habilidades = new List<habilidad>();
            habilidades.Add(nueva);
            estado = 'A';
            turnos = 0;
        }

        ~NPC()
        {
            habilidades.Clear();
        }

        public void setNombre(string nom)
        {
            nombre = nom;
        }

        public void setVidaMax(int vida)
        {
            vidaMax = vida;
        }

        public void setVidaAct(int vida)
        {
            vidaActual = vida;
        }

        public void setppMax(int pp)
        {
            ppMax = pp;
        }

        public void setppAct(int pp)
        {
            ppActual = pp;
        }

        public void setNivel(int niv)
        {
            nivel = niv;
        }

        public string getNombre()
        {
            return nombre;
        }

        public override int getVidaMax()
        {
            return vidaMax;
        }

        public override int getVidaAct()
        {
            return vidaActual;
        }

        public int getppMax()
        {
            return ppMax;
        }

        public int getppAct()
        {
            return ppActual;
        }

        public int getNivel()
        {
            return nivel;
        }

        public int getID()
        {
            return ID;
        }

        public void setID(int id)
        {
            ID = id;
        }

        public char getSexo()
        {
            return sexo;
        }

        public void setSexo(char sex)
        {
            sexo = sex;
        }

        public bool getMasked()
        {
            return masked;
        }

        public void setMasked(bool mask)
        {
            masked = mask;
        }

        public override int getBO()
        {
            return BO;
        }
        public void setBO(int bo)
        {
            BO = bo;
        }
        public override int getBD()
        {
            return BD;
        }
        public void setBD(int bd)
        {
            BD = bd;
        }
        public bool getBomasked()
        {
            return bomasked;
        }
        public void setBomasked(bool mask)
        {
            bomasked = mask;
        }
        public bool getBdmasjed()
        {
            return bdmasked;
        }
        public void setBdmadked(bool mask)
        {
            bdmasked = mask;
        }

        public List<habilidad> gethabilidades()
        {
            return habilidades;
        }

        public void sethabilidad(List<habilidad> habs)
        {
            habilidades.Clear();
            habilidades.AddRange(habs);
        }

        public void setnuevahabilidad(habilidad hab)
        {
            habilidades.Add(hab);
        }

        public char getestado()
        {
            return estado;
        }

        public void setestado(char e)
        {
            estado = e;
        }

        public int getturnos()
        {
            return turnos;
        }

        public void setturnos(int t)
        {
            turnos = t;
        }

        public List<listahechizos> getlistahechizos()
        {
            return lista_hehcizos;
        }

        public bool guardar(string nombre)
        {
            try
            {
                string filename;
                
                filename = nombre;
                
                XmlTextWriter save = new XmlTextWriter(filename, null);
                save.Formatting = Formatting.Indented;
                save.WriteStartDocument();
                save.WriteStartElement("NPC");
                save.WriteAttributeString("id", Convert.ToString(ID));
                save.WriteElementString("nombre", nombre);
                save.WriteElementString("vida", Convert.ToString(vidaActual));
                save.WriteElementString("vidamax", Convert.ToString(vidaMax));
                save.WriteElementString("pp", Convert.ToString(ppActual));
                save.WriteElementString("ppmax", Convert.ToString(ppMax));
                save.WriteElementString("nivel", Convert.ToString(nivel));
                save.WriteElementString("sexo", Convert.ToString(sexo));
                if (masked == true)
                {
                    save.WriteElementString("sexmasked", "true");
                }
                else
                {
                    save.WriteElementString("sexmasked", "false");
                }
                save.WriteElementString("BO", Convert.ToString(BO));
                if (bomasked == true)
                {
                    save.WriteElementString("BOmasked", "true");
                }
                else
                {
                    save.WriteElementString("BOmasked", "false");
                }

                save.WriteElementString("BD", Convert.ToString(getBD()));
                if (getBdmasjed() == true)
                {
                    save.WriteElementString("bdmasked", "true");
                }
                else
                {
                    save.WriteElementString("bdmasked", "false");
                }
                save.WriteElementString("estado", Convert.ToString(getestado()));
                save.WriteElementString("turnos", Convert.ToString(getturnos()));
                if (gethabilidades() != null)
                {
                    List<habilidad> hab = gethabilidades();
                    for (int i = 0; i < hab.Count; i++)
                    {
                        save.WriteStartElement("habilidad");
                        save.WriteAttributeString("atr1", hab[i].getatributo1());
                        save.WriteAttributeString("atr2", hab[i].getatributo2());
                        save.WriteAttributeString("coste1", Convert.ToString(hab[i].getcoste1()));
                        save.WriteAttributeString("coste2", Convert.ToString(hab[i].getcoste2()));
                        save.WriteAttributeString("coste3", Convert.ToString(hab[i].getcoste3()));
                        save.WriteElementString("nombre", hab[i].getnombre());
                        save.WriteElementString("descripcion", hab[i].getdescripcion());
                        save.WriteElementString("rango", Convert.ToString(hab[i].getrango()));
                        save.WriteEndElement();
                    }
                }
                if (getlistahechizos() != null)
                {
                    List<listahechizos> lhech = getlistahechizos();
                    for (int i = 0; i < lhech.Count; i++)
                    {
                        save.WriteStartElement("lista_hechizos");
                        save.WriteAttributeString("nivel", Convert.ToString(lhech[i].getnivel()));
                        save.WriteAttributeString("reino", lhech[i].getreino());
                        List<hechizo> hech = lhech[i].gethechizos();
                        for (int j = 0; j < hech.Count; j++)
                        {
                            save.WriteStartElement("hechizo");
                            save.WriteAttributeString("nivel", Convert.ToString(hech[j].getlvl()));
                            save.WriteElementString("nombre", hech[j].getnombre());
                            save.WriteElementString("descripcion", hech[j].getdesc());
                            save.WriteElementString("daño", Convert.ToString(hech[j].getdaño()));
                            save.WriteElementString("critico", Convert.ToString(hech[j].getcritico()));
                            save.WriteElementString("tipo_critico", hech[j].gettipocritico());
                            save.WriteEndElement();
                        }
                        save.WriteEndElement();
                    }
                }

                save.WriteEndElement();
                save.WriteEndDocument();

                save.Flush();
                save.Close();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool cargar(string ruta)
        {
            return true;
        }
    }
}
